package com.mingtu.jgspatrol.activity;

import static com.mingtu.jgspatrol.utils.MyConstant.ItemDecorationSpaces;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.view.Gravity;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.PathUtils;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;
import com.hjq.gson.factory.GsonFactory;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.luck.picture.lib.basic.PictureMediaScannerConnection;
import com.luck.picture.lib.entity.LocalMedia;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.interfaces.OnConfirmListener;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Progress;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okserver.OkDownload;
import com.lzy.okserver.download.DownloadListener;
import com.lzy.okserver.download.DownloadTask;
import com.lzy.okserver.task.XExecutor;
import com.mingtu.common.base.BaseApplication;
import com.mingtu.common.callback.StringDialogCallback;
import com.mingtu.common.utils.Constant;
import com.mingtu.common.utils.IntentUtils;
import com.mingtu.common.utils.MyLogUtil;
import com.mingtu.common.utils.MyUtills;
import com.mingtu.common.utils.SpacesItemDecoration;
import com.mingtu.jgspatrol.R;
import com.mingtu.jgspatrol.adapter.NewsAttachAdapter;
import com.mingtu.jgspatrol.base.MyBaseActivity;
import com.mingtu.jgspatrol.bean.NewDetailsBean;
import com.mingtu.jgspatrol.databinding.ActivityNewsDetailsBinding;
import com.mingtu.jgspatrol.share.BottomPopupShare;
import com.mingtu.jgspatrol.utils.MyConstant;
import com.mob.MobSDK;
import com.mob.moblink.ActionListener;
import com.mob.moblink.MobLink;
import com.mob.moblink.Scene;
import com.mob.moblink.SceneRestorable;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.tencent.smtt.sdk.QbSdk;
import com.tencent.smtt.sdk.ValueCallback;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cn.sharesdk.onekeyshare.OnekeyShare;
import cn.sharesdk.wechat.favorite.WechatFavorite;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;

public class NewsDetailsActivity extends MyBaseActivity<ActivityNewsDetailsBinding> implements SceneRestorable, XExecutor.OnAllTaskEndListener {
    private BasePopupView popupView;
    private String id;
    private String title;
    private String myPath;
    private String textContent;
    private List<NewDetailsBean.ContentInfoBean.InformationAttachEntitiesBean> DataBean = new ArrayList<>();
    private NewsAttachAdapter newsAttachAdapter;
    private OkDownload okDownload;
    private String fileDirectory = PathUtils.getExternalDownloadsPath();
    private List<String> images = new ArrayList<>();
    private ArrayList<LocalMedia> LocalMediaList = new ArrayList<>();
    private String filePath;
    private String savePath = PathUtils.getExternalDownloadsPath();
    private String docName = "";
    private DownloadTask downloadTask;
    private String docUrl;
    private String typeName;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_news_details;
    }

    @Override
    protected void initView() {
        super.initView();
        setModuleTitle("新闻详情");
    }

    @Override
    protected void initData() {
        initPullRefresh();
        LinearLayoutManager manager1 = new LinearLayoutManager(context);
        binding.recyclerAttach.setLayoutManager(manager1);
        binding.recyclerAttach.addItemDecoration(new SpacesItemDecoration(0, 0, ItemDecorationSpaces, ItemDecorationSpaces, ItemDecorationSpaces));

        newsAttachAdapter = new NewsAttachAdapter(DataBean);
        binding.recyclerAttach.setAdapter(newsAttachAdapter);
        newsAttachAdapter.setOnItemClickListener(new NewsAttachAdapter.OnItemClickListener() {

            @Override
            public void onItemClick(View view, int position) {
                newsAttachDealEvent(position);
            }
        });
        typeName = getIntent().getStringExtra("typeName");
        String notice = getIntent().getStringExtra("notice");
        if (!StringUtils.isEmpty(typeName)) {
            setModuleTitle(typeName);
        }
        if (!StringUtils.isEmpty(notice)) {
            setModuleTitle("单位通知");
        }
    }

    private void newsAttachDealEvent(int position) {
        XXPermissions.with(NewsDetailsActivity.this)
                // 不适配 Android 11 可以这样写
//                .permission(Permission.Group.STORAGE)
                // 适配 Android 11 需要这样写，这里无需再写 Permission.Group.STORAGE
                .permission(Permission.MANAGE_EXTERNAL_STORAGE)
                .request(new OnPermissionCallback() {
                    @Override
                    public void onGranted(List<String> permissions, boolean all) {
                        if (permissions.contains(Permission.MANAGE_EXTERNAL_STORAGE)) {
                            ToastUtils.showLong("文件下载中...");
                            okDownload = OkDownload.getInstance();
                            okDownload.addOnAllTaskEndListener(NewsDetailsActivity.this);
                            NewDetailsBean.ContentInfoBean.InformationAttachEntitiesBean entitiesBean = DataBean.get(position);
                            docUrl = entitiesBean.getUrl();
                            docName = entitiesBean.getName();
                            filePath = savePath + "/" + docName;

                            if (StringUtils.isEmpty(docName)) {
                                ToastUtils.showLong("文件读取错误！");
                                return;
                            }

                            if (StringUtils.isEmpty(docUrl)) {
                                ToastUtils.showLong("文件链接错误！");
                                return;
                            }

                            XXPermissions.with(NewsDetailsActivity.this)
                                    .permission(Permission.WRITE_SETTINGS)
                                    .request(new OnPermissionCallback() {
                                        @Override
                                        public void onGranted(List<String> permissions, boolean all) {
                                            if (permissions.contains(Permission.WRITE_SETTINGS)) {
                                                //如果文件存在
                                                if (FileUtils.isFileExists(filePath)) {
                                                    openFileReader(filePath);
                                                } else {
                                                    //文件不存在 ,下载完成之后打开
                                                    downloadDocFile();
                                                }
                                            }
                                        }

                                        @Override
                                        public void onDenied(List<String> permissions, boolean never) {
                                            if (never) {
                                                // 如果是被永久拒绝就跳转到应用权限系统设置页面
                                                ToastUtils.showLong("请手动授予修改系统设置权限");
                                                XXPermissions.startPermissionActivity(NewsDetailsActivity.this, permissions);
                                            } else {

                                            }

                                        }
                                    });
                        }
                    }

                    @Override
                    public void onDenied(List<String> permissions, boolean never) {
                        if (never) {
                            // 如果是被永久拒绝就跳转到应用权限系统设置页面
                            new XPopup.Builder(NewsDetailsActivity.this)
                                    .isDestroyOnDismiss(true)
                                    .dismissOnTouchOutside(true)
                                    .hasShadowBg(true)
                                    .asConfirm(context.getResources().getString(R.string.text_tip), context.getResources().getString(R.string.text_storage_auth),
                                            context.getResources().getString(R.string.text_cancle), context.getResources().getString(R.string.text_sure),
                                            new OnConfirmListener() {
                                                @Override
                                                public void onConfirm() {
                                                    XXPermissions.startPermissionActivity(NewsDetailsActivity.this, permissions);
                                                }
                                            }, null, false)
                                    .show();
                        }
                    }
                });
    }

    @Override
    protected void getData() {
        String content = getIntent().getStringExtra("detail");
        WebSettings webSettings = binding.webView.getSettings();
        webSettings.setDisplayZoomControls(false); //隐藏webview缩放按钮
        webSettings.setJavaScriptEnabled(true);//支持js
//        webSettings.setBuiltInZoomControls(true); // 显示放大缩小
//        webSettings.setSupportZoom(true); // 可以缩放
        webSettings.setUseWideViewPort(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setTextZoom(230);
        webSettings.setStandardFontFamily("family");
        webSettings.setMediaPlaybackRequiresUserGesture(false);
        binding.webView.addJavascriptInterface(new JavascriptInterface(this), "imagelistner");
        binding.webView.setWebViewClient(new MyWebViewClient());

        if (!StringUtils.isEmpty(content)) {
            binding.webView.loadDataWithBaseURL(null, new HtmlFormat().getNewContent(content), "text/html", "UTF-8", null);
        } else {
            if (StringUtils.isEmpty(myPath)) {
                id = getIntent().getStringExtra("id");
                getNewDetails(id);
            }
//            showTopRightImg(R.mipmap.icon_share_white); //只有新闻详情能够分享
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (okDownload != null) {
            okDownload.removeOnAllTaskEndListener(this);
        }
        if (downloadTask != null) {
            downloadTask.remove();
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        MobLink.updateNewIntent(getIntent(), this);
    }

    @Override
    protected void onClickTitlebarRight(View view) {
        super.onClickTitlebarRight(view);
        //分享
        BottomPopupShare bottomPopup = new BottomPopupShare(this);
        bottomPopup.setOnItemClickListener(new BottomPopupShare.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                popupView.dismiss();

                // 设置场景参数
                HashMap<String, Object> senceParams = new HashMap();
                senceParams.put("id", id);// 新建场景
                Scene s = new Scene();
                s.path = MyConstant.getInstance().NEWS_DETAILS_PATH;
                s.params = senceParams;
                // 请求场景ID
                MobLink.getMobID(s, new ActionListener<String>() {
                    @Override
                    public void onResult(String s) {
                        String mobID = s;
                        String content = "绿水青山就是金山银山";
                        if (!StringUtils.isEmpty(title)) {
                            content = title;
                        }
//                        Bitmap imageData = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);
                        Bitmap imageData = MyUtills.drawable2Bitmap(context.getResources().getDrawable(R.drawable.bg_shared_img));
                        final OnekeyShare oks = new OnekeyShare();

                        // titleUrl是标题的网络链接，仅在Linked-in,QQ和QQ空间使用
                        oks.setText(content);
                        // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间使用
                        oks.setTitle(content);
                        oks.setTitleUrl("https://www.mingtukeji.com");
                        // text是分享文本，所有平台都需要这个字段
                        //分享网络图片，新浪微博分享网络图片需要通过审核后申请高级写入接口，否则请注释掉测试新浪微博
//                        oks.setImageUrl("http://f1.sharesdk.cn/imgs/2014/02/26/owWpLZo_638x960.jpg");
                        // url仅在微信（包括好友和朋友圈）中使用
                        oks.setImageData(imageData);
                        oks.setUrl("https://www.mingtukeji.com/jzApp/news_detail.html?id=" + id + "&mobid=" + mobID);
                        if (position == 0) {
                            //好友
                            //指定分享的平台，如果为空，还是会调用九宫格的平台列表界面
                            oks.setText(getShareText(textContent));
                            oks.setPlatform(Wechat.NAME);
                            oks.show(MobSDK.getContext());
                        } else if (position == 1) {
                            //朋友圈
                            oks.setPlatform(WechatMoments.NAME);
                            oks.show(MobSDK.getContext());
                        } else if (position == 2) {
                            //收藏
                            oks.setPlatform(WechatFavorite.NAME);
                            oks.show(MobSDK.getContext());
                        }

                    }

                    @Override
                    public void onError(Throwable throwable) {

                    }
                });


            }
        });
        popupView = new XPopup.Builder(this)
                .moveUpToKeyboard(false) //如果不加这个，评论弹窗会移动到软键盘上面
                .enableDrag(true)
                .isDarkTheme(true)
                .navigationBarColor(getResources().getColor(R.color.black))
                .isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
//                        .isThreeDrag(true) //是否开启三阶拖拽，如果设置enableDrag(false)则无效
                .asCustom(bottomPopup)
                .show();
    }

    @Override
    protected void onClickedTopLeftButtton(View view) {
        if (!StringUtils.isEmpty(myPath)) {
            //从分享页面跳转过来
            IntentUtils.getInstance().readyGo(NewsDetailsActivity.this, MainActivity.class);
        }
        super.onClickedTopLeftButtton(view);
    }

    private void initPullRefresh() {
        binding.srlUp.setEnableLoadMore(false);
        binding.srlUp.setEnableOverScrollDrag(true);
        binding.srlUp.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                binding.srlUp.finishRefresh(Constant.REFRESH_TIME);
                binding.srlUp.setNoMoreData(false);
            }
        });
    }

    @Override
    public void onReturnSceneData(Scene scene) {
        myPath = scene.getPath();
        HashMap<String, Object> hashMap = scene.getParams();
        if (hashMap != null) {
            if (hashMap.containsKey("id")) {
                String id = String.valueOf(hashMap.get("id"));
                getNewDetails(id);
            }
        }
    }

    @Override
    public void onAllTaskEnd() {
        ToastUtils.showLong("下载完成，文件保存在：" + fileDirectory);
        //下载完成后移除异常监听
        if (okDownload != null) {
            okDownload.removeOnAllTaskEndListener(this);
        }
        if (downloadTask != null) {
            downloadTask.remove();
        }
    }


    public class HtmlFormat {
        public String getNewContent(String htmltext) {
            Document doc = Jsoup.parse(htmltext);
            Elements elements = doc.getElementsByTag("img");
            for (Element element : elements) {
                element.attr("width", "100%").attr("height", "auto");
            }
            return doc.toString();
        }
    }

    /**
     * 分享时候的内容
     *
     * @return
     */
    private String getShareText(String textContent) {
        String text = "用科技服务生态";
        if (!StringUtils.isEmpty(textContent)) {
            //先判断title和内容的title是不是一样
            if (!StringUtils.isEmpty(title)) {
                if (textContent.indexOf(title) != -1) {//内容含有title
                    String myContent = textContent.substring(title.length() - 1, textContent.length());
                    if (myContent.length() >= 35) {
                        text = myContent.substring(0, 35);
                    } else {
                        text = myContent;
                    }
                } else {
                    if (textContent.length() >= 35) { //内容不含有title
                        text = textContent.substring(0, 35);
                    } else {
                        text = textContent;
                    }
                }
            } else {
                if (textContent.length() >= 35) { //内容不含有title
                    text = textContent.substring(0, 35);
                } else {
                    text = textContent;
                }
            }

        }
        return text;
    }

    /**
     * 获取新闻列表
     *
     * @param id
     */
    private void getNewDetails(String id) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("id", id);
        hashMap.put("type", "app");
        String str = GsonUtils.toJson(hashMap);
        OkGo.<String>post(MyConstant.POST_NEWS_DETAILS)
                .tag(this)
                .upJson(str)
                .execute(new StringDialogCallback(this) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        if (!StringUtils.isEmpty(result)) {

                            Gson gson = GsonFactory.getSingletonGson();
                            NewDetailsBean newDetailsBean = new NewDetailsBean();
                            newDetailsBean = gson.fromJson(result, NewDetailsBean.class);
                            NewDetailsBean.ContentInfoBean contentInfoBean = newDetailsBean.getContentInfo();
                            if (contentInfoBean != null) {
                                title = contentInfoBean.getContentTitle();
                                String contentBody = contentInfoBean.getContentBody();
                                String time = contentInfoBean.getCreateTime();
                                String contentImg = contentInfoBean.getContentImg();
                                String source = contentInfoBean.getSource();
                                List<NewDetailsBean.ContentInfoBean.InformationAttachEntitiesBean> entitiesBeans = contentInfoBean.getInformationAttachEntities();

                                binding.layoutAttach.setVisibility(View.GONE);
                                if (entitiesBeans != null) {
                                    if (entitiesBeans.size() > 0) {
                                        newsAttachAdapter.upData(entitiesBeans);
                                        binding.layoutAttach.setVisibility(View.VISIBLE);
                                        DataBean.addAll(entitiesBeans);
                                    }
                                }


                                if (!StringUtils.isEmpty(time)) {
                                    binding.tvTime.setText("发布时间：" + time);
                                }

                                if (!StringUtils.isEmpty(source)) {
                                    binding.tvSource.setText("来源：" + source);
                                }

                                if (!StringUtils.isEmpty(title)) {
                                    binding.tvTitle.setText(title + "");
                                    binding.tvTitle.setVisibility(View.VISIBLE);
                                    binding.tvTitle.post(() -> {
                                        if (binding.tvTitle.getLineCount() > 1)
                                            //多余一行左对齐
                                            binding.tvTitle.setGravity(Gravity.LEFT);
                                        else
                                            //一行中间对齐
                                            binding.tvTitle.setGravity(Gravity.CENTER_HORIZONTAL);
                                    });
                                }

//                                if (!StringUtils.isEmpty(contentImg) && contentBody.indexOf("<img") == -1) {
//                                    contentBody = "<p><img src=\"" + contentImg + "\" style=\"max-width:100%;\" contenteditable=\"false\"/></p>";
//                                }
                                if (!StringUtils.isEmpty(contentImg) && !StringUtils.isEmpty(typeName) && !typeName.contains("工作动态")) {
                                    contentBody = "<p><img src=\"" + contentImg + "\" style=\"max-width:100%;\" contenteditable=\"false\"/></p>" + contentBody.trim();

                                }

                                if (!StringUtils.isEmpty(contentBody)) {
                                    binding.webView.loadDataWithBaseURL(null, new HtmlFormat().getNewContent(contentBody.trim()), "text/html", "UTF-8", null);

                                    String regFormat = "\\s*|\t|\r|\n";
                                    String regTag = "<[^>]*>";
                                    try {
                                        textContent = contentBody.replaceAll(regFormat, "")
                                                .replaceAll(regTag, "")
                                                .replaceAll("&nbsp;", "");
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }


                            }

                        }
                    }
                });
    }

    /**
     * 实现对WebView的监听管理
     */
    public class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // 得到 URL 可以传给应用中的某个 WebView 页面加载显示
//                view.loadUrl(url);
            if (!StringUtils.isEmpty(url)) {
                WebView.HitTestResult hit = view.getHitTestResult();
                if (hit != null) {
                    int hitType = hit.getType();
                    if (hitType == WebView.HitTestResult.SRC_ANCHOR_TYPE
                            || hitType == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {// 点击超链接
                        Intent i = new Intent(Intent.ACTION_VIEW);
                        i.setData(Uri.parse(url));
                        startActivity(i);
                    } else {
                        view.loadUrl(url);
                    }
                } else {
                    view.loadUrl(url);
                }
            } else {
                ToastUtils.showLong("链接地址无效哦！");
            }

            return true;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            view.getSettings().setJavaScriptEnabled(true);
            super.onPageFinished(view, url);
            addImageClickListener(view);//待网页加载完全后设置图片点击的监听方法
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            view.getSettings().setJavaScriptEnabled(true);
            super.onPageStarted(view, url, favicon);
        }

        private void addImageClickListener(WebView webView) {
            webView.loadUrl("javascript:(function(){" +
                    "var objs = document.getElementsByTagName(\"img\"); " +
                    "for(var i=0;i<objs.length;i++) " +
                    "{" +
                    "window.imagelistner.readImageUrl(objs[i].src,i); " +
                    " objs[i].onclick=function() " +
                    " { " +
                    " window.imagelistner.openImage(this.src); " + //通过js代码找到标签为img的代码块，设置点击的监听方法与本地的openImage方法进行连接
                    " } " +
                    "}" +
                    "})()");
        }
    }

    /**
     * 用来实现js调用本地的方法
     */
    public class JavascriptInterface {

        private Context context;

        public JavascriptInterface(Context context) {
            this.context = context;
        }

        @android.webkit.JavascriptInterface
        public void readImageUrl(String img, int position) {  //把所有图片的url保存在ArrayList<String 中
            images.add(img); // 为了点击的时候查找索引
            LocalMedia localMedia = LocalMedia.generateHttpAsLocalMedia(img);
            LocalMediaList.add(localMedia);
        }

        @android.webkit.JavascriptInterface //对于targetSdkVersion =17的，要加这个声明
        public void openImage(String img)//点击图片所调用到的函数
        {
            int position = images.indexOf(img);
            BaseApplication.initPreviewModel().startActivityPreview(position, false, LocalMediaList);

        }
    }

    /**
     * 下载文件
     */
    private void downloadDocFile() {
        if (StringUtils.isEmpty(docUrl)) {
            ToastUtils.showLong("未获取到文件链接！");
            return;
        }

        GetRequest<File> request = OkGo.<File>get(docUrl);
        downloadTask = OkDownload.request(docUrl, request);
        downloadTask.folder(savePath);
        downloadTask.fileName(docName);
        downloadTask.register(new DownloadListener(docUrl) {
            @Override
            public void onStart(Progress progress) {
                showDownLoadDialog();
            }

            @Override
            public void onProgress(Progress progress) {

            }

            @Override
            public void onError(Progress progress) {
                hideDownLoadDialog();
                ToastUtils.showLong(getResources().getString(R.string.text_download_fail));
            }

            @Override
            public void onFinish(File file, Progress progress) {
                //扫描更新媒体库
                hideDownLoadDialog();
//                MediaScannerConnection.scanFile(context, new String[]{savePath}, null, null);
                new PictureMediaScannerConnection(context, file.getAbsolutePath(), () -> {
                });
                ToastUtils.showLong(getResources().getString(R.string.text_download_success));

                openFileReader(filePath);

                docUrl = null;
                docName = null;

            }

            @Override
            public void onRemove(Progress progress) {

            }
        });
        downloadTask.save();
        downloadTask.start();
    }

    /**
     * 打开下载的文件
     */
    private void openFileReader(String filePath) {
        HashMap<String, String> params = new HashMap<>();
        params.put("local", "true");
        try {
            JSONObject Object = new JSONObject();
            Object.put("pkgName", getApplicationContext().getPackageName());
            params.put("menuData", Object.toString());
            QbSdk.getMiniQBVersion(NewsDetailsActivity.this);
            int ret = QbSdk.openFileReader(NewsDetailsActivity.this, filePath, params, new ValueCallback<String>() {
                @Override
                public void onReceiveValue(String s) {
                    MyLogUtil.e("testest", "====**====" + s);

                }
            });
            //1：用QQ浏览器打开 2：用MiniQB打开 3：调起阅读器弹框 -1：filePath为空 打开失败 -5：高版本Android没有定义ContentProvider -6：打开apk类型的文件uri解析为空 -7：fileType为空
            switch (ret) {
                case -1:
                    ToastUtils.showLong("打开失败，文件地址有误!");
                    break;
                case -5:
                    ToastUtils.showLong("高版本Android没有定义ContentProvider!");
                    break;
                case -6:
                    ToastUtils.showLong("打开apk类型的文件uri解析为空!");
                    break;
                case -7:
                    ToastUtils.showLong("fileType为空!");
                    break;
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}